<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 1.  先打开注册页 => 输入数据提交(默认跳转登录)
    // 2.  登录页解析数据  http://127.0.0.1:5500/day17/html/login.html?user=zxczxc&pwd=zxczxc&phone=17386141516&email=1272071496%40qq.com  
    // 找到参数数据队列  user=zxczxc&pwd=zxczxc&phone=17386141516&email=1272071496%40qq.com 
    // 3. 解析该参数数据队列的数据 存放到对象中

    // 注册页 提交数据   登录页解析数据?
    // var data = {
    //     user:"a123123",
    //     pwd:"123123",
    //     phone:"17386141517",
    //     email:"=1272071496%40qq.com"
    // }

    var search = location.search;
    console.log(search);
    var data = {};
    if(search){
        var str = search.substring(1);
        console.log(str);
        var list = str.split("&");
        console.log(list);
        for(var i=0;i<list.length;i++){
            var item = list[i];  // 'user=a123123', 'pwd=123123', 
            var arr = item.split("=");
            console.log(arr);
            var key = arr[0];  // var key = item.split("=")[0];  "user" "pwd"
            var val = arr[1];  
            console.log(key,val);

            data[key] = decodeURIComponent(val);
        }
        console.log(data);

    }else{
        location.href = "./register.html";
    }


    function urlParse(){
        var search = location.search;
        var data = {};
        if(search){
            var str = search.substring(1);
            var list = str.split("&");
            for(var i=0;i<list.length;i++){
                var item = list[i];  // 'user=a123123', 'pwd=123123', 
                var arr = item.split("=");
                var key = arr[0];  // var key = item.split("=")[0];  "user" "pwd"
                var val = arr[1];  
                data[key] = decodeURIComponent(val);
            }
        }
        return data;
    }

</script>
</html>